#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
const int N = 510;
char g[N][N];
int dist[N][N];
bool st[N][N];
int t,n,m;
typedef pair<int, int> PII;

int bfs()
{
    deque<PII>q;
    memset(dist,0x3f,sizeof dist);
    memset(st,0,sizeof st);
    dist[0][0]=0;
    q.push_back({0,0});
    char cs[]="\\/\\/";
    int dx[]={-1,-1,1,1},dy[]={-1,1,1,-1};
    int ix[]={-1,-1,0,0},iy[]={-1,0,0,-1};
    
    while(q.size())
    {
        auto t=q.front();
        q.pop_front();
        
        int x=t.first,y=t.second;
        if(x==n&&y==m)return dist[x][y];
        if(st[x][y])continue;
        st[x][y]=true;
        for(int i=0;i<4;i++)
        {
            int a=x+dx[i],b=y+dy[i];
            if(a<0||a>n||b<0||b>m)continue;
            int ga=x+ix[i],gb=y+iy[i];
            int w=(g[ga][gb]!=cs[i]);
            int d=dist[x][y]+w;
            if(d<dist[a][b])
            {
                dist[a][b]=d;
                if(w==0)q.push_front({a,b});
                else q.push_back({a,b});
            }
        }
        
    }
}

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d", &n, &m);
        for(int i=0;i<n;i++)scanf("%s",g[i]);
        if((n+m)%2==1)cout<<"NO SOLUTION\n";
        else printf("%d\n",bfs());
    }
    return 0;
}
